package org.example;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.util.Date;

/**
 * Hello world!
 *
 */
public class QueueProduceerMain
{
    public static void main( String[] args ) throws Exception {
        createProducerQueue();
        System.out.println("发送成功");
    }


    public static void createProducerQueue() throws JMSException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://192.168.20.158:61617");
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("liurq.active.queue");
        MessageProducer mp = session.createProducer(queue);
        for(int i = 0 ;i < 20;i++){
            TextMessage textMessage = session.createTextMessage("hello liurq.active.queue " + i + " " + System.currentTimeMillis());
            mp.send(textMessage);
        }
        mp.close();;
        session.close();
        connection.close();
    }

}
